<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Cconfig{
	private $data = array();
	
  	public function __construct() {
		$CI =& get_instance();
		
		$CI->db->from('setting');	
		$CI->db->where('store_id',0);
		$query = $CI->db->get();	
		
		foreach ($query->result_array() as $setting) {
			
				if (!$setting['serialized']) {
					$this->set($setting['key'], $setting['value']);
				} else {
					$this->set($setting['key'], unserialize($setting['value']));
				}				
			
		}
	}

  	public function get($key) {
    	return (isset($this->data[$key]) ? $this->data[$key] : null);
  	}	
	
	public function set($key, $value) {
    	$this->data[$key] = $value;
  	}

	public function has($key) {
    	return isset($this->data[$key]);
  	}

  	public function load($filename) {
		$file = DIR_CONFIG . $filename . '.php';
		
    	if (file_exists($file)) { 
	  		$cfg = array();
	  
	  		require($file);
	  
	  		$this->data = array_merge($this->data, $cfg);
		} else {
			exit('Error: Could not load config ' . $filename . '!');
		}
  	}
}
?>